home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
wics.zip
/
DEDTWIN.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-05
|
11KB
|
462 lines
#include <dedtwin.h>
TDemoEditWindow::TDemoEditWindow (PTWindowsObject AParent, LPSTR ATitle, LPSTR AFile)
: TFileWindow (AParent, ATitle, AFile)
{
lf.lfHeight = -13 ;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_REGULAR;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut = FALSE;
lf.lfCharSet = ANSI_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH || FF_SWISS;
lstrcpy ( lf.lfFaceName, "Arial");
hFont = CreateFontIndirect (&lf);
fr.lStructSize = sizeof(FINDREPLACE);
fr.hInstance = GetApplication()->hInstance;
fr.Flags = FR_DOWN | FR_MATCHCASE | FR_SHOWHELP;
fr.lpstrFindWhat = new char[128];
fr.lpstrReplaceWith = new char [128];
fr.wFindWhatLen = 128;
fr.wReplaceWithLen = 128;
lstrcpy (fr.lpstrFindWhat, "");
lstrcpy (fr.lpstrReplaceWith, "");
}
TDemoEditWindow::~TDemoEditWindow()
{
DeleteObject (hFont);
}
void TDemoEditWindow::GetWindowClass(WNDCLASS _FAR & AWndClass)
{
TFileWindow::GetWindowClass(AWndClass);
AWndClass.hIcon = LoadIcon(GetApplication()->hInstance, MAKEINTRESOURCE(FILE_ICON));
}
void TDemoEditWindow::SetupWindow ()
{
TFileWindow::SetupWindow();
SendMessage (Editor->HWindow, WM_SETFONT, hFont, 0L);
}
void TDemoEditWindow::DefWndProc (RTMessage Msg)
{
if ( Msg.Message == GetParent()->idFindTextMessage )
{
LPFINDREPLACE lpfr ;
lpfr = (LPFINDREPLACE) Msg.LParam ;
if ( lpfr->Flags & FR_REPLACE )
ReplaceEditorText ();
else
if ( lpfr->Flags & FR_REPLACEALL )
ReplaceAllEditorText ();
else
if ( !(lpfr->Flags & FR_DIALOGTERM) )
FindEditorText ();
else
TFileWindow::DefWndProc(Msg);
}
else
TFileWindow::DefWndProc(Msg);
}
void TDemoEditWindow::ReplaceEditorText ()
{
if ( Editor->Search(-1, fr.lpstrFindWhat, fr.Flags & FR_MATCHCASE) != -1 )
Editor->Insert ( fr.lpstrReplaceWith );
}
void TDemoEditWindow::ReplaceAllEditorText ()
{
while ( Editor->Search (-1, fr.lpstrFindWhat, fr.Flags & FR_MATCHCASE) != -1 )
Editor->Insert ( fr.lpstrReplaceWith );
}
void TDemoEditWindow::WMCommand (RTMessage msg)
{
if ( HIWORD(msg.LParam) == EN_SETFOCUS )
ENSetFocus();
if ( HIWORD(msg.LParam) == EN_KILLFOCUS )
ENKillFocus();
TFileWindow::WMCommand(msg);
}
void TDemoEditWindow::CMFind (RTMessage)
{
int StartPos, EndPos ;
fr.hwndOwner = HWindow;
fr.Flags = FR_DOWN | FR_MATCHCASE | FR_SHOWHELP;
Editor->GetSelection(StartPos, EndPos);
if ( StartPos != EndPos )
Editor->GetSubText (fr.lpstrFindWhat, StartPos, EndPos);
else
lstrcpy (fr.lpstrFindWhat, "");
FindText (&fr);
}
void TDemoEditWindow::CMReplace (RTMessage)
{
int StartPos, EndPos ;
fr.hwndOwner = HWindow;
fr.Flags = FR_DOWN | FR_MATCHCASE | FR_SHOWHELP;
Editor->GetSelection(StartPos, EndPos);
if ( StartPos != EndPos )
Editor->GetSubText (fr.lpstrFindWhat, StartPos, EndPos);
else
lstrcpy (fr.lpstrFindWhat, "");
ReplaceText (&fr);
}
void TDemoEditWindow::CMPrint (RTMessage)
{
PTDemoPrintedPage DemoPrintout = 0;
if ( GetPrinter() )
{
DemoPrintout = new TDemoPrintedPage ("WICS Demo", Editor, &lf);
GetPrinter()->Print (GetParent(), DemoPrintout);
delete DemoPrintout ;
}
}
TDemoPrintedPage::TDemoPrintedPage (Pchar ATitle, PTEdit pe, LOGFONT FAR * lplf)
: TPrintedPage(ATitle)
{
AnEditor = pe;
lpLogFont = lplf;
iLine = 0 ;
iOffsetToLine = 0;
fAnotherPage = TRUE;
}
void TDemoPrintedPage::PrintPage (HDC hdc, WORD, POINT PageSize, POINT dpi)
{
HFONT hFont;
LPSTR lpLine;
DWORD lExtent;
LOGFONT lf;
int iPrevLine;
int Pagecx;
int Pagecy;
int PointSize;
int i, n;
int length;
int x, y ;
const UnitsPerInch = 100 ;
Pagecx = (int)((long)PageSize.x * UnitsPerInch / dpi.x) ;
Pagecy = (int)((long)PageSize.y * UnitsPerInch / dpi.y) ;
PointSize = GetPointSize (lpLogFont); // Get the point size of the font
lpLine = new char [256]; // Allocate a buffer for the input line
_fmemmove (&lf, lpLogFont, sizeof(LOGFONT)); // Copy the LOGFONT structure
iPrevLine = -1;
SaveDC (hdc); // Save the Device Context on the stack
SetMapMode (hdc, MM_LOENGLISH); // Set the mapping mode
lf.lfHeight = 0 - (int)((long) PointSize * UnitsPerInch / 72) ;
hFont = CreateFontIndirect (&lf); // Create the printer font
SelectObject (hdc, hFont); // Select the printer font
SetTextColor (hdc, RGB(0,0,0)); // Set Text Color to Black
lExtent = GetTextExtent (hdc, "A", 1); // Get the line height
x = (0.50 * UnitsPerInch); // 1/2 inch border
y = 0 - x ; // 1/2 inch border
for ( i = iLine ; i < AnEditor->GetNumLines() && 0 - y < Pagecy ; )
{
length = AnEditor->GetLineLength(i);
if ( length > 0 )
{
if ( length > 256 )
length = 255 ;
if ( i != iPrevLine )
{
AnEditor->GetLine(lpLine, length, i);
iPrevLine = i ;
}
lExtent = GetTextExtent (hdc, (lpLine+iOffsetToLine), lstrlen(lpLine+iOffsetToLine));
if ( LOWORD(lExtent) < Pagecx )
{
TextOut (hdc, x, y, (lpLine+iOffsetToLine), lstrlen(lpLine+iOffsetToLine));
iOffsetToLine = 0;
iLine++;
i++;
}
else
{
n = lstrlen(lpLine) - 1 ;
lExtent = GetTextExtent (hdc, (lpLine+iOffsetToLine), n - iOffsetToLine) ;
while ( LOWORD(lExtent) > Pagecx && n > iOffsetToLine )
{
while ( *(lpLine+n) == ' ' && n > iOffsetToLine )
n--;
while ( *(lpLine+n) != ' ' && n > iOffsetToLine )
n-- ;
if ( n > iOffsetToLine )
lExtent = GetTextExtent (hdc, (lpLine+iOffsetToLine), n - iOffsetToLine) ;
}
if ( n > iOffsetToLine )
{
TextOut (hdc, x, y, (lpLine+iOffsetToLine), n - iOffsetToLine);
iOffsetToLine = n ;
while ( *(lpLine+iOffsetToLine) != 0x00 && *(lpLine+iOffsetToLine) == ' ' )
iOffsetToLine++;
if ( *(lpLine+iOffsetToLine) == 0x00 )
{
iOffsetToLine = 0;
iLine++;
i++;
}
}
else
{
TextOut (hdc, x, y, (lpLine+iOffsetToLine), lstrlen(lpLine+iOffsetToLine));
iOffsetToLine = 0;
iLine++;
i++;
}
}
}
else
{
iPrevLine = i;
iOffsetToLine = 0;
iLine++;
i++;
}
y -= HIWORD(lExtent);
}
if ( i < AnEditor->GetNumLines() )
fAnotherPage = TRUE ;
else
fAnotherPage = FALSE ;
RestoreDC (hdc, -1);
DeleteObject (hFont);
delete lpLine;
}
void TDemoEditWindow::ENSetFocus ()
{
BOOL fBold;
BOOL fItalic;
fBold = ( lf.lfWeight > FW_REGULAR ) ;
fItalic = (BOOL)lf.lfItalic;
GetParent()->SetIconBarButtonState (IBID_BOLD, fBold);
GetParent()->SetIconBarButtonState (IBID_ITALIC, fItalic);
GetParent()->SetFontStyle(&lf);
EnableMenuEntry (CM_FILESAVE);
EnableMenuEntry (CM_FILESAVEAS);
EnableMenuEntry (CM_PRINT);
EnableMenuEntry (CM_EDITUNDO);
EnableMenuEntry (CM_EDITCUT);
EnableMenuEntry (CM_EDITCOPY);
EnableMenuEntry (CM_EDITPASTE);
EnableMenuEntry (CM_EDITCLEAR);
EnableMenuEntry (CM_CHANGEFONT);
EnableMenuEntry (CM_SELECTCOLOR);
EnableMenuEntry (CM_FIND);
EnableMenuEntry (CM_REPLACE);
}
void TDemoEditWindow::ENKillFocus ()
{
DisableMenuEntry (CM_FILESAVE);
DisableMenuEntry (CM_FILESAVEAS);
DisableMenuEntry (CM_PRINT);
DisableMenuEntry (CM_EDITUNDO);
DisableMenuEntry (CM_EDITCUT);
DisableMenuEntry (CM_EDITCOPY);
DisableMenuEntry (CM_EDITPASTE);
DisableMenuEntry (CM_EDITCLEAR);
DisableMenuEntry (CM_CHANGEFONT);
DisableMenuEntry (CM_SELECTCOLOR);
DisableMenuEntry (CM_FIND);
DisableMenuEntry (CM_REPLACE);
}
void TDemoEditWindow::CMFontChanged (RTMessage)
{
HFONT hOldFont ;
GetParent()->GetIconBar()->GetSelectedFontFamilyName(LF_FACESIZE-1,lf.lfFaceName);
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE ;
hOldFont = hFont;
hFont = CreateFontIndirect(&lf);
SendMessage (Editor->HWindow, WM_SETFONT, hFont, MAKELPARAM(TRUE,0));
DeleteObject (hOldFont);
}
void TDemoEditWindow::CMFontSizeChanged (RTMessage)
{
HFONT hOldFont;
lf.lfHeight = GetParent()->GetIconBar()->GetSelectedFontSize();
hOldFont = hFont;
hFont = CreateFontIndirect(&lf);
SendMessage (Editor->HWindow, WM_SETFONT, hFont, MAKELPARAM(TRUE,0));
DeleteObject (hOldFont);
}
void TDemoEditWindow::CMBold (RTMessage)
{
BOOL fBold ;
HFONT hOldFont;
if ( lf.lfWeight > FW_REGULAR )
{
lf.lfWeight -= 300 ;
fBold = FALSE;
}
else
{
lf.lfWeight += 300 ;
fBold = TRUE ;
}
GetParent()->GetIconBar()->SetButtonState (IBID_BOLD, fBold);
hOldFont = hFont;
hFont = CreateFontIndirect(&lf);
SendMessage (Editor->HWindow, WM_SETFONT, hFont, MAKELPARAM(TRUE,0));
DeleteObject (hOldFont);
}
void TDemoEditWindow::CMItalic (RTMessage)
{
BOOL fItalic ;
HFONT hOldFont;
fItalic = !(BOOL) lf.lfItalic ;
lf.lfItalic = fItalic ;
GetParent()->GetIconBar()->SetButtonState (IBID_ITALIC, fItalic);
hOldFont = hFont;
hFont = CreateFontIndirect(&lf);
SendMessage (Editor->HWindow, WM_SETFONT, hFont, MAKELPARAM(TRUE,0));
DeleteObject (hOldFont);
}
void TDemoEditWindow::CMChangeFont (RTMessage)
{
CHOOSEFONT cf;
cf.lStructSize = sizeof(CHOOSEFONT);
cf.hwndOwner = HWindow;
cf.hDC = NULL;
cf.lpLogFont = &lf;
cf.Flags = CF_ANSIONLY | CF_TTONLY | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT | CF_SHOWHELP ;
cf.rgbColors = rgbTextColor;
cf.lCustData = NULL;
cf.lpfnHook = NULL;
cf.lpTemplateName = NULL;
cf.hInstance = NULL;
cf.lpszStyle = NULL;
cf.nFontType = 0;
cf.nSizeMin = 0;
cf.nSizeMax = 0;
if ( ChooseFont (&cf) )
{
DeleteObject (hFont);
hFont = CreateFontIndirect(&lf);
SendMessage (Editor->HWindow, WM_SETFONT, hFont, MAKELPARAM(TRUE,0));
}
}
void TDemoEditWindow::CMFileSaveAs (RTMessage)
{
OPENFILENAME ofn ;
LPSTR szDefaultDirectory;
szDefaultDirectory = new char[128];
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = HWindow;
ofn.hInstance = GetApplication()->hInstance;
ofn.lpstrFilter = "All Files\x00*.*\x00\x00\x00";
ofn.lpstrCustomFilter = NULL;
ofn.nMaxCustFilter = 0;
ofn.nFilterIndex = 1;
ofn.lpstrFile = new char[128];
ofn.nMaxFile = 128;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = szDefaultDirectory;
ofn.lpstrTitle = "Save File";
ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_SHOWHELP | OFN_NOREADONLYRETURN ;
ofn.nFileOffset = 0;
ofn.nFileExtension = 0;
ofn.lpstrDefExt = "DAT";
ofn.lCustData = NULL;
ofn.lpfnHook = NULL;
ofn.lpTemplateName = NULL;
lstrcpy (ofn.lpstrFile, FileName);
lstrcpy (szDefaultDirectory, "C:\\");
if ( GetSaveFileName (&ofn) )
{
SetFileName(ofn.lpstrFile);
Write();
}
delete szDefaultDirectory;
delete ofn.lpstrFile;
}